from django import forms
from django.contrib import admin
from .models import CephCluster, GlobalConfig, ApiAllowIP


@admin.register(CephCluster)
class CephClusterAdmin(admin.ModelAdmin):
    admin_order = 3
    list_display_links = ('name',)
    list_display = ('id', 'name', 'disable_choice', 'priority_stored_value', 'cluster_name', 'user_name', 'pool_names',
                    'config_file', 'keyring_file', 'modified_time', 'remarks')
    search_fields = ['name']
    ordering = ('disable_choice', 'priority_stored_value')

    def get_actions(self, request):
        actions = super().get_actions(request)
        if 'delete_selected' in actions:
            del actions['delete_selected']

        return actions


class GlobalConfigModelAdminForm(forms.ModelForm):
    class Meta:
        model = GlobalConfig
        fields = '__all__'  # 或者指定需要包含的字段
        widgets = {
            'remark': forms.Textarea(attrs={'rows': 3, 'cols': 100}),  # 调整文本框的大小
        }

@admin.register(GlobalConfig)
class GlobalConfigTableAdmin(admin.ModelAdmin):
    admin_order = 1
    form = GlobalConfigModelAdminForm
    list_display_links = ('id',)
    list_display = ('id', 'name', 'content', 'remark', 'create_time', 'modif_time')


@admin.register(ApiAllowIP)
class ApiAllowIPAdmin(admin.ModelAdmin):
    admin_order = 2
    list_display_links = ('id',)
    list_display = ('id', 'ip_value', 'remark', 'creation_time', 'update_time',)
